﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace GetEmailAddress
{
    class Program
    {
        static void Main(string[] args)
        {
         
            #region  old
            Obj o10 = new Obj() { EndIndex = 4180, StartIndex = 1, UserID = 1 };
            Obj o11 = new Obj() { StartIndex = 1001, EndIndex = 2000, UserID = 2 };
            Obj o12 = new Obj() { StartIndex = 2001, EndIndex = 3000, UserID = 2 };
            Obj o20 = new Obj() { EndIndex = 4180, StartIndex = 3001, UserID = 3 };
            Thread t10 = ThreadFactory.CreateThread(o10);
            Thread t11 = ThreadFactory.CreateThread(o11);
            Thread t12 = ThreadFactory.CreateThread(o12);

            Thread t21 = ThreadFactory.CreateThread(o20);
            List<Thread> lists = new List<Thread>();
            lists.Add(t10);
            //lists.Add(t11); lists.Add(t12); lists.Add(t21);

            foreach (var list in lists)
            {
                list.Start();
            }

            foreach (var list in lists)
            {
                list.Join();
            }
            // Obj o21 = new Obj() { StartIndex = 610001, EndIndex = 700000, UserID = 4 };
            // Obj o22 = new Obj() { StartIndex = 700001, EndIndex = 800000, UserID = 5 };


            // Obj o30 = new Obj() { EndIndex = 1000000, StartIndex = 936601, UserID = 6 };
            // Obj o31 = new Obj() { StartIndex = 1000001, EndIndex = 1100000, UserID = 7 };




            // Obj o40 = new Obj() { EndIndex = 1300000, StartIndex = 1236701, UserID = 8 };
            // Obj o41 = new Obj() { StartIndex = 1300001, EndIndex = 1400000, UserID = 9 };
            // Obj o42 = new Obj() { StartIndex = 14000001, EndIndex = 1411000, UserID = 10 };



            //Thread t10 = ThreadFactory.CreateThread(o10);
            //Thread t11 = ThreadFactory.CreateThread(o11);
            //Thread t12 = ThreadFactory.CreateThread(o12);

            //Thread t21 = ThreadFactory.CreateThread(o20);
            //Thread t22 = ThreadFactory.CreateThread(o21);
            //Thread t20 = ThreadFactory.CreateThread(o22);

            //Thread t30 = ThreadFactory.CreateThread(o30);
            //Thread t31 = ThreadFactory.CreateThread(o31);


            //Thread t41 = ThreadFactory.CreateThread(o40);
            //Thread t42 = ThreadFactory.CreateThread(o41);
            //Thread t40 = ThreadFactory.CreateThread(o42);

            // t10.Start();
            // t11.Start();
            // t12.Start();
            // t20.Start();
            // t21.Start();
            // t22.Start();
            // t30.Start();
            // t31.Start();
            // t40.Start();
            // t41.Start();
            // t42.Start();


            // t11.Join();
            // t20.Join();
            // t12.Join();
            // t21.Join();
            // t22.Join();
            // t30.Join();
            // t42.Join();
            // t31.Join();
            // t40.Join();
            // t41.Join();
            // t10.Join();
           


            #endregion


            SqlHelper s = new SqlHelper();
            s.WriteForm(new Obj { StartIndex = 400, EndIndex = 500 });
            Console.ReadKey();
        }
    }
    public class Info
    {
        public int UserID { set; get; }
        public string EmailAddress { set; get; }
        public int OperationUserID { set; get; }
    }

    public class Obj
    {
        public int UserID { set; get; }

        public int StartIndex { set; get; }

        public int EndIndex { set; get; }
    }

    public class ThreadFactory
    {
        public static Thread CreateThread(Obj o)
        {
            OperationMethod operation = new OperationMethod() { O = o };
            Thread t1 = new Thread(new ThreadStart(operation.DO));

            return t1;
        }


    }

    public class OperationMethod
    {

        public Obj O { set; private get; }

        public void DO()
        {
            SqlHelper s = new SqlHelper();
            s.WriteForm(O);

        }
    }

}




